from django.db import models


# Create your models here.

class JobModel(models.Model):
    # 基础信息
    brand_name = models.CharField(
        max_length=50, verbose_name='公司名称', blank=False)
    job_name = models.CharField(max_length=50, verbose_name='岗位名称')
    scope = models.CharField(max_length=50, verbose_name='公司规模')
    salary_desc = models.CharField(max_length=20, verbose_name='薪资区间')
    stage = models.BooleanField(verbose_name='是否融资', default=False)
    welfare = models.CharField(max_length=100, verbose_name='福利待遇', blank=True)

    # 地理信息
    city_name = models.CharField(max_length=10, verbose_name='所在城市')
    area_district = models.CharField(
        max_length=20, verbose_name='所在城市区域', blank=True)

    # 技术信息
    language = models.CharField(max_length=40, verbose_name='编程语言', blank=True)
    skills = models.CharField(max_length=100, verbose_name='技术标签')
    job_exp = models.CharField(max_length=20, verbose_name='工作经验')
    job_degree = models.CharField(max_length=20, verbose_name='学历要求')

    # 爬虫信息
    data_from = models.CharField(max_length=20, verbose_name='数据来源')

    # 赋值方法 | model_to_dict可以快速拷贝
    def set_fields(self, brand_name, job_name, scope, salary_desc, stage, welfare, city_name, area_district, skills,
                   job_exp, job_degree, data_from, lang):
        self.brand_name = brand_name
        self.job_name = job_name
        self.scope = scope
        self.salary_desc = salary_desc
        self.stage = stage
        self.welfare = welfare
        self.city_name = city_name
        self.area_district = area_district
        self.skills = skills
        self.job_exp = job_exp
        self.job_degree = job_degree
        self.data_from = data_from
        self.language = lang

    def __str__(self):
        return f"{self.brand_name} - {self.job_name} - {self.scope} - {self.salary_desc}"


class JobCal(models.Model):
    job = models.ForeignKey(
        JobModel, on_delete=models.CASCADE, verbose_name='外键-JobModel')
    average_salary = models.FloatField(verbose_name='平均工资', blank=True)


class JsonFile(models.Model):
    # title = models.CharField(max_length=255, blank=False)
    file = models.FileField(upload_to='uploads/', max_length=20000)
